﻿<UserControl x:Class="DALT.Controls.ItemsControlAdornerExample"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             xmlns:controls="clr-namespace:DALT.Controls"
             xmlns:behaviors="clr-namespace:DALT.Controls.Behaviors"
             xmlns:converters="clr-namespace:DALT.Controls.Converters">

    <!-- THIS IS AN EXAMPLE IMPLEMENTATION TO DEMONSTRATE ItemsControlAdorner -->

    <!-- SET THE DATACONTEXT TO THE VIEWMODEL 
    <UserControl.DataContext>
        <my:SomeViewModel /> 
    </UserControl.DataContext> -->

    <!-- SET ANY CONVERTERS OR OTHER RESOURCES YOU MAY NEED -->
    <UserControl.Resources>
        
        <!-- <converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" /> 
             etc
             etc -->

        <!-- SET A DATA TEMPLATE FOR THE ItemsControlAdorner
        <DataTemplate x:Key="MyObjectDetailsTemplate" DataType="{x:Type my:MyObject}" >
            <Border Background="#BBFFFFFF" BorderBrush="DarkOrchid" BorderThickness="1" CornerRadius="5" TextElement.Foreground="DarkOrchid" >
                <Grid Margin="5" Width="300">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Some Property (1)" />
                    <TextBox Grid.Row="1" Text="{Binding SomeProperty1, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock  Grid.Row="2" Text="Some Property (2)" />
                    <TextBox Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding SomeProperty2}" />
                    <TextBlock Grid.Column="1" Text="Some Binary Enum Property" />
                    <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" >
                        <RadioButton Content="Option1" IsChecked="{Binding SomeBinaryEnumProperty, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static my:SomeBinaryEnum.Option1}}" />
                        <RadioButton Content="Option2" IsChecked="{Binding SomeBinaryEnumProperty, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static my:SomeBinaryEnum.Option2}}" />
                    </StackPanel>
                    <Button x:Name="PART_CloseButton" Grid.Column="2" Height="16">
                        <Button.Template>
                            <ControlTemplate>
                                <Border Background="#01FFFFFF" Padding="3" >
                                    <Path Stretch="Uniform" ClipToBounds="True" Stroke="DarkOrchid" StrokeThickness="2.5" 
                                          Data="M 85.364473,6.9977109 6.0640998,86.29808 6.5333398,85.76586 M 6.9926698,7.4977169 86.293043,86.79809 85.760823,86.32885"  />
                                </Border>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Grid>
            </Border>
        </DataTemplate> -->

        
        <!-- THIS STYLE DETERMINES THE APPEARANCE OF THE ITEMS IN THE ITEMSCONTROL -->
        <Style x:Key="ItemAsButtonStyle" TargetType="{x:Type Button}" >
       <!-- <Setter Property="Foreground" Value="White" />
            <Setter Property="FontFamily" Value="Times New Roman" />
            <Setter Property="Background" Value="#CC99E6" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="MinHeight" Value="24" />
            <Setter Property="Margin" Value="3,2" />
            <Setter Property="Padding" Value="3,2" />
            <Setter Property="Border.CornerRadius" Value="8" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border CornerRadius="{TemplateBinding Border.CornerRadius}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" 
                                Padding="{TemplateBinding Padding}" 
                                Margin="{TemplateBinding Margin}" >
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter> -->
        </Style>

        
        <!-- THIS STYLE SETS THE TEMPLATE FOR THE ITEMS PANEL (THE CONTAINER) AND FOR THE ITEMS THEMSELVES; 
               IN THIS EXAMPLE THEY ARE DISPLAYED AS BUTTONS. 
               CLICKING THE "BUTTON" SHOWS THE ADORNER FOR INLINE EDITING/MESSAGING/WHATEVER -->
        
        <Style x:Key="MyItemsControlStyle" TargetType="{x:Type ItemsControl}">
            <!-- <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter> -->
        
            <!-- <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Button x:Name="button" Style="{StaticResource ItemAsButtonStyle}" Content="{Binding SomeProperty1}" >
                            <i:Interaction.Behaviors>
                                <behaviors:ShowAdornerBehavior DataTemplate="{StaticResource MyObjectDetailsTemplate}" />
                            </i:Interaction.Behaviors>
                        </Button>
                    </DataTemplate>
                </Setter.Value>
            </Setter> -->
        </Style>
    </UserControl.Resources>

    <!-- THE REST OF THE USERCONTROL JUST DISPLAYS THE ITEMS -->
    <Grid>
        <ItemsControl ItemsSource="{Binding SomeCollection}" Style="{StaticResource MyItemsControlStyle}" />
    </Grid>

</UserControl>